<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增参数')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-config-add" name="form-config-add" >
        <h4 class="form-header h4">模型类型添加</h4>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">模型类型名称：</label>
                    <div class="col-sm-8">
                        <input id="typeName" name="typeName" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="form-group">
                <div class="col-sm-12">
                    <label class="col-sm-4  control-label is-required">模型类型封面上传：</label>
                    <div class="col-sm-7">
                        <input
                                id="file"
                                name="file"
                                data-show-preview="true"
                                type="file"
                                multiple
                                data-max-file-count="1"
                                data-theme="fas">
                    </div>
                </div>
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix = ctx + "system/modelType";

    $(document).ready(function () {
        $("#file").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': '#',
            initialPreviewAsData: true,
            autoReplace:true,
            showRemove:false,
            showUpload:false,
            layoutTemplates :{
                actionDelete:'', //去除上传预览的缩略图中的删除图标
                actionUpload:'',//去除上传预览缩略图中的上传图片；
                actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
            }
        });
    });

    $("#form-config-add").validate({
        onkeyup: false,
        rules: {
            typeName: {
                remote: {
                    url: prefix + "/checkModelTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "typeName": function() {
                            return $.common.trim($("#typeName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return data;
                    }
                }
            }
        },
        messages: {
            "typeName": {
                remote: "该模型类型已存在"
            }
        },
        focusCleanup: true
    });


    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData($('#form-config-add')[0]);
            formData.append('file', $('#file')[0].files[0]);

            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }
</script>
</div>
</body>

</html>
